/**
 * Created by tanbingqin on 2020/1/16.
 */
import {messages} from "share/common";
/**
 * 操作：评论
 * 适用：非编辑状态 且 customFormPropertyMap['approval.discuss']为true 的 申请单
 */
import React from 'react'
import { connect } from 'react-redux'
import menuRoute from 'routes/menuRoute'
import { Form, Button, message, Modal } from 'antd'
import ApproveMention from 'components/template/approve-mention'

class MentionBtn extends React.Component{
  constructor(props) {
    super(props);
    this.state = {
      mentionVisible: false
    }
  }

  //关闭评论弹框
  //isSuccess 是否是成功的评论
  handleCloseMention = (isSuccess) => {
    const { goBack } = this.props;
    this.setState({mentionVisible: false});
    if (isSuccess && goBack) {
      goBack(true);
    }
  };

  render() {
    const { mentionVisible } = this.state;
    const { info, customFormPropertyMap, entityType, entityOID } = this.props;
    return (
      <div className="travel-update-btn request-btn" style={{ display: 'inline-block' }}>
        {(customFormPropertyMap && customFormPropertyMap['approval.discuss'] === 'true') && (
          <Button type="primary" onClick={() => this.setState({mentionVisible: true})}>{messages('request-1.key104')/*评论*/}</Button>
        )}
        <ApproveMention
          mentionVisible={mentionVisible}
          onClose={this.handleCloseMention}
          entities={{
            entityOID: entityOID || info.applicationOID,
            entityType: entityType
          }}
          customFormPropertyMap={customFormPropertyMap}
        />
      </div>
    )
  }
}

MentionBtn.propTypes = {
  info: React.PropTypes.object,
  customFormPropertyMap: React.PropTypes.object,
  goBack: React.PropTypes.func,
  entityType: React.PropTypes.number,
  entityOID: React.PropTypes.string
};

MentionBtn.defaultProps = {
  entityType: 1001
};

MentionBtn.contextTypes = {
  router: React.PropTypes.object
};

function mapStateToProps() {
  return { }
}

export default connect(mapStateToProps)(MentionBtn)
